/**
 * @file lv_100ask_japanese_ime.c
 *
 */

/*********************
 *      INCLUDES
 *********************/
#include "lv_japanese_ime.h"
#include "lv_100ask_pinyin_ime.h"
#if LV_USE_100ASK_japanese_IME != 0
#include <stdio.h>

/*********************
 *      DEFINES
 *********************/
#define MY_CLASS    &lv_100ask_japanese_ime_class

uint16_t py_page;           /* Current pinyin map pages */
uint16_t py_num[26];        /* Number and length of Pinyin */
uint16_t py_pos[26];        /* Pinyin position */


/**********************
 *      TYPEDEFS
 **********************/

/**********************
 *  STATIC PROTOTYPES
 **********************/

static lv_100ask_dict_t * japanese_search_matching_dict(lv_obj_t * obj, char * strInput_py_str, uint16_t * cand_num);
/**********************
 *  STATIC VARIABLES
 **********************/

                                                

#define LV_100ASK_japanese_IME_DEFAULT_PIN_YIN_DICT 1
#if LV_100ASK_japanese_IME_DEFAULT_PIN_YIN_DICT
lv_100ask_dict_t lv_100ask_def_japanese_dict[] = {
            {"a","あ","阿 安 亜 哀 愛"},
            {"ageru","あげる","上"},
            {"ai","あい","合会 相愛 挨拶 愛 藍 挨 曖 哀"},
            {"ak","あく","悪 圧 旭 訳 握"},
            {"akeru","あける","開"},
            {"akira","あきら","晶 晃 昭 暁 玲"},
            {"aku","あく","渇 握 灰 亜 飽 悪 開 扱 宛"},
            {"ame","あめ","雨 飴 天"},
            {"ami","あみ","網 雨 天 飴 亜美"},
            {"an","あん","暗 杏 闇 案 鞍"},
            {"ano","あの","阿野 安野"},
            {"ao","あお","青 蒼 葵 応 凹"},
            {"aru","ある","有"},
            {"atsu","あつ","厚"},
            {"atsui","あつい","暑"},
            {"au","あう","会"},
            {"ayumi","あゆみ","歩 亜由美"},
            {"ba","ば","場 婆 馬 罵 波 罰 把"},
            {"bai","ばい","陪 賠 倍 梅"},
            {"ban","ばん","番 晩 版 藩 盤"},
            {"bangumi","ばんぐみ","番組"},
            {"basu","ばす","バス"},
            {"batsu","ばつ","伐 閥 抜 罰"},
            {"be","べ","部 倍 陪 辺 弁"},
            {"ben","べん","便 弁 変 勉 偏"},
            {"benkyou","べんきょう","勉強"},
            {"bi","び","備 美 非 悲 尾"},
            {"bo","ぼ","母 坊 防 房 棒 望"},
            {"bou","ぼう","棒 坊 防 房 帽 忘 貿 冒"},
            {"bu","ぶ","武 撫 侮 部 分 夫 舞 不"},
            {"bya","びゃ","秒"},
            {"byo","びょ","描"},
            {"byou","びょう","病 錨 秒 評 苗 豹"},
            {"byu","びゅ","苗"},
            {"cha","ちゃ","茶"},
            {"chi","ち","千 知 血 地 乳 恥 秩 致 稚 置 治 値 遅 池 散 鎮 珍 陳 朕 賃 沈 錆 緻 蜘 痴 蔦 茅"},
            {"cho","ちょ","長 鳥 帳 町 庁"},
            {"chou","ちょう","帳 聴 庁 懲 町 長 鳥 調 張 兆"},
            {"chu","ちゅ","中 注 宙 昼 柱 衷 鋳 酎 駐 厨 弔 彫 凋 貼"},
            {"da","だ","打 駄 妥 堕 惰 唾 舵 楕 陀 騨 鐓 沱 躱 田"},
            {"dai","だい","台 岱 代 第 題"},
            {"daichi","だいち","大地 大智"},
            {"dan","だん","弾 段 団 談 壇 男 断"},
            {"de","で","出 代 伝 電 庭 泥 弟 呈 締 艇 鄭 釘 手 台"},
            {"densha","でんしゃ","電車"},
            {"denwa","でんわ","電話"},
            {"deru","でる","出"},
            {"dji","ぢ",""},
            {"do","ど","度 土 道 同 堂 奴 怒 刀 徒 斗 努 呑 胴 動 銅 導 働 洞 憧 瞳 萄 峠 慟 藤 籐"},
            {"dou","どう","動 導 堂 銅 胴 働 道 瞳 同"},
            {"dzu","づ",""},
            {"e","え","絵 得 江 延 縁 円 園 援 液 鋭 疫 悦 謁 越 餌 厭 堰 婉 媛 曳 洩 羨 閲 襟 奄 鋳 重 柄 駅 枝"},
            {"ei","えい","映 永 栄 曳 泳"},
            {"en","えん","縁 援 艶 塩 円 宴 演"},
            {"eru","える","得"},
            {"fu","ふ","夫 布 不 付 府 負 風 婦 父 富 分 普 腐 敷 賦 赴 符 扶 附 譜 侮 阜 膚 芙 斧 浮 斑 噴 墳 紛 雰 鮒 麩 蕗 封 俯 輔"},
            {"fuchi","ふち","淵 縁"},
            {"fune","ふね","船 舟"},
            {"fusa","ふさ","房 総 纐"},
            {"futo","ふと","太 不図"},
            {"ga","が","画 賀 我 牙 雅 餓 駕 臥 俄 峨 蛾 伽 侃 瓦 霓"},
            {"gai","がい","害 慨 街 涯 該 外 蓋"},
            {"gakkou","がっこう","学校"},
            {"gan","がん","翫 眼 願 玩 岸 岩 癌 顔"},
            {"garasu","がらす","硝子"},
            {"ge","げ","下 化 牙 介 械 外 解 芸 劇 削 崖 慨 卦 戯 碍 霓"},
            {"gi","ぎ","戯 儀 擬 技 議 偽 疑 義 祇 妓 宜 岐 欺 犠 魏 蟻 伎 杵 誼 跪 祁 沂 鵜"},
            {"gin","ぎん","銀"},
            {"go","ご","後 語 護 誤 呉 娯 悟 碁 御 梧 伍 吾 傲 檎 蜈 鯉 午 五"},
            {"gou","ごう","号 合 郷 剛 壕 業 豪"},
            {"gu","ぐ","具 愚 呉 誤 獄 偶 遇 虞 寓 隅 喰 駆 勲 禺 鵜 釧 グ"},
            {"gun","ぐん","軍 群 郡 薫 訓"},
            {"gya","ぎゃ","逆"},
            {"gyo","ぎょ","魚"},
            {"gyu","ぎゅ","牛"},
            {"ha","は","波 派 配 敗 拝 歯 葉 琶 破 把 覇 刃 端 播 羽 杷 芭 婆 皐 洟 罰 八"},
            {"hahaki","ははき","帚 箒"},
            {"hai","はい","灰 廃 配 拝 杯 貝"},
            {"hajimeru","はじめる","始"},
            {"hakaru","はかる","核 課 測 格 計 校 較 謀 量 諮 図"},
            {"hakobu","はこぶ","運"},
            {"han","はん","判 犯 反 搬 版"},
            {"hana","はな","花"},
            {"hanasu","はなす","話"},
            {"hane","はね","羽 跳 撥"},
            {"harau","はらう","払"},
            {"haruka","はるか","遥 春香 悠"},
            {"hata","はた","旗 畑 機 幡"},
            {"he","へ","辺 返 平 壁 部 戸 閉 畑"},
            {"hei","へい","併 蔽 閉 平 兵"},
            {"hen","へん","変 返 編 篇 偏 遍"},
            {"henji","へんじ","返事"},
            {"heya","へや","部屋"},
            {"hi","ひ","比 非 飛 肥 皮 日 火 妃 扉 費 被 悲 秘 罷 彼 疲 披 避 卑 碑 庇 泌 姫 緋 誹 譬 柊 樋 瓢 鵯"},
            {"hige","ひげ","髭 鬚 顎"},
            {"hikouki","ひこうき","飛行機"},
            {"himo","ひも","紐 絆"},
            {"hin","ひん","賓 品 貧 頻"},
            {"hiraku","ひらく","開"},
            {"hito","ひと","人 一 瞳"},
            {"ho","ほ","保 法 方 奉 歩 補 報 豊 放 捕 舗 穂 募 甫 輔 頬 鵬 呆 俸 倣 吠 剖 蓬 砲 墓 訪"},
            {"hon","ほん","本"},
            {"hoshi","ほし","星"},
            {"hotoke","ほとけ","仏 仏陀"},
            {"hou","ほう","俸 法 報 方 鵬 胞 傍 包"},
            {"hya","ひゃ","百 兵 表 瓢 票 標"},
            {"hyo","ひょ","表 氷 票 評 標 漂 豹 剽 瓢 雹 鰾 謬 驃 驫"},
            {"hyou","ひょう","票 標 表 瓢 漂 氷 評"},
            {"hyu","ひゅ","標"},
            {"i","い","以 位 意 委 医 井 衣 異 囲 移 維 胃 威 依 尉 伊 違 慰 緯 椅 為 畏 萎 蔚 亥 咽 藹 易 夷 稲 謂 瑚 磯 惟"},
            {"ichiban","いちばん","一番 逸般"},
            {"ie","いえ","家"},
            {"iku","いく","育 郁 幾 行 逝"},
            {"in","いん","印 姻 咽 因 員"},
            {"inochi","いのち","命"},
            {"ireru","いれる","入"},
            {"ishi","いし","石 意志 医師"},
            {"isogu","いそぐ","急"},
            {"isu","いす","椅子"},
            {"iu","いう","言"},
            {"ja","じゃ","邪"},
            {"ji","ぢ","地 治 蒂 弛 遅"},
            {"ji","じ","自 字 次 寺 時 磁 事 璽"},
            {"jikan","じかん","時間"},
            {"jin","じん","迅 腎 人 陣 神"},
            {"jitsu","じつ","嫉 実 蔭 失 日"},
            {"jo","じょ","助"},
            {"jou","じょう","丞 条 嬢 尉 情 状 上 常"},
            {"ju","じゅ","授 受 儒 需"},
            {"juu","じゅう","住 銃 十 重 獣"},
            {"ka","か","加 可 歌 化 火 家 荷 夏 科 果 仮 価 河 過 佳 架 賀 華 貨 課 蚊 禍 稼 嫁 寡 戈 苛 渦 菓 迦 嘩 伽 珂 禾 鎌 楷"},
            {"kabe","かべ","壁"},
            {"kaeru","かえる","帰"},
            {"kai","かい","会 階 海 開 貝 回 改 界 晦 潰 介 戒"},
            {"kaimono","かいもの","買い物 買物"},
            {"kaisha","かいしゃ","会社"},
            {"kaito","かいと","海斗 翔人 楓"},
            {"kakaru","かかる","掛 懸 係"},
            {"kaku","かく","書 描"},
            {"kakunin","かくにん","確認"},
            {"kan","かん","間 幹 勧 陥 観 監 感 韓 官"},
            {"kangae","かんがえ","考え"},
            {"katsu","かつ","勝"},
            {"kawa","かわ","川 河 側 皮 革"},
            {"kawaii","かわいい","可愛"},
            {"kaze","かぜ","風 風邪 数"},
            {"ke","け","家 気 形 景 計 軽 経 化 系 型 決 劇 激 欠 血 潔 結 穴 傑 件 倹 健 券 剣 圏 堅 賢 嫌 憲 懸 拳 検 絹 謙 顕 犬 訣 繭 鎌 鹸 絢 硯 掻 蹴 桁 罫 恵 渓 仮 下 兄"},
            {"kei","けい","型 系 茎 形 径"},
            {"kekkon","けっこん","結婚"},
            {"ken","けん","権 県 軒 倹 剣 顕 検 健 鍵"},
            {"ki","き","機 期 基 気 記 木 起 貴 帰 危 紀 規 希 奇 季 喜 旗 既 寄 器 幾 企 揮 亀 祈 軌 輝 騎 飢 鬼 岐 嬉 棋 棄 肌 毀 畿 毅 喫 菊 徽 伎 杵 忌 綺 稀 蟻 饗 黄 聞"},
            {"kiku","きく","聴 聞"},
            {"kimeru","きめる","決"},
            {"kin","きん","金"},
            {"kinyou","きんよう","金曜"},
            {"kiru","きる","切 着"},
            {"ko","こ","故 個 子 古 湖 公 港 小 戸 粉 呼 庫 腰 越 候 虚 濃 誇 顧 鼓 娯 胡 呉 虎 孤 弧 枯 糊 股 乞 此 箇 姑 菰 鯉 籠 甑 怙 梠 高 校 光"},
            {"ko","ご","語"},
            {"kokoro","こころ","心"},
            {"koku","こく","国"},
            {"koppu","こっぷ","骨杯"},
            {"koto","こと","事"},
            {"kotoba","ことば","言葉 詞"},
            {"kou","こう","工 鋼 公 坑 光 喉 功 溝 港 侯 高"},
            {"ku","く","区 苦 句 久 工 国 黒 薬 九 具 駆 空 繰 来 公 狗 偶 遇 愚 虞 惧 括 掘 靴 窟 熊 粂 釧 葛 沓 椛 鞍 駈 口"},
            {"kuchi","くち","口"},
            {"kumo","くも","雲 蜘蛛 曇"},
            {"kuni","くに","国"},
            {"kuro","くろ","黒"},
            {"kuru","くる","来 呉 繰"},
            {"kuruma","くるま","車"},
            {"kya","きゃ","霞 峡 怯 客"},
            {"kyo","きょ","許"},
            {"kyou","きょう","教 協 兇 強 匡"},
            {"kyu","きゅ","九 級 弓 宮 急 吸 糾 丘 旧 笈 汲 灸 鳩 厩 驂"},
            {"kyuu","きゅう","泣 及 弓 級 宮 九"},
            {"ma","ま","間 真 万 末 摩 馬 魔 麻 磨 満 漫 未 味 魅 毎 枚 妹 昧 膜 繭 麿 槇 茉 瑪 鰻"},
            {"machi","まち","町"},
            {"mado","まど","窓"},
            {"mai","まい","毎 舞 枚 麦 埋"},
            {"matsu","まつ","待"},
            {"me","め","目 女 芽 馬 売 飯 前 妻 姪 雌 牝 銘 冥 瞑 妹 迷 滅"},
            {"mei","めい","盟 名 銘 命 冥 明 姪"},
            {"men","めん","門 麺 面 綿 悶 免"},
            {"mi","み","見 美 未 実 身 民 味 視 脈 魅 巳 箕 弥 御 深 蜜 密 岬 三 参 診 壬 澪 瑞 耳"},
            {"min","みん","眠 岷 民"},
            {"minori","みのり","実 稔 美野里"},
            {"miru","みる","見"},
            {"mizu","みず","水 瑞"},
            {"mo","も","毛 物 望 百 莫 茂 模 喪 裳 木 猛 母 燃 戻 催 黙 藻 耗 蒙 儲 勿 餅 尤 罠"},
            {"mon","もん","問 文 紋 門"},
            {"morau","もらう","貰"},
            {"mori","もり","森"},
            {"motsu","もつ","持"},
            {"mou","もう","妄 毛 猛 網"},
            {"mu","む","無 務 夢 武 六 娘 矛 霧 牟 婿 埋 鵡 椋 厩 絢"},
            {"mura","むら","村"},
            {"mya","みゃ","宮 麿 苗 明 鳴 瞑"},
            {"myo","みょ","命"},
            {"myu","みゅ","無 妙 夢 名 民 蜜"},
            {"n","ん","無"},
            {"na","な","名 奈 南 那 菜 波 浪 無 内 納 捺 娜 凪 訥 衲"},
            {"nadeshiko","なでしこ","撫子"},
            {"nagi","なぎ","凪 薙"},
            {"nai","ない","無 内 奈 那 耐 災 皆"},
            {"naka","なか","中"},
            {"nami","なみ","波 並 浪"},
            {"naoto","なおと","直人 尚斗"},
            {"naru","なる","成 鳴 生 為"},
            {"natsu","なつ","夏 捺"},
            {"nawa","なわ","縄 繩"},
            {"ne","ね","根 音 寝 練 値 熱 子 年 粘 祢 寧 葱 鼠 捻 涅 稔 廿 禰 猫"},
            {"neko","ねこ","猫 寝子"},
            {"nen","ねん","粘 念 年 燃"},
            {"ni","に","二 日 爾 荷 虹 新 任 人 似 煮 尼 児 丹 妊 賑 匂 邇 珥 迩 韮 鰯 仁"},
            {"nichi","にち","日"},
            {"niji","にじ","虹 二次"},
            {"nin","にん","認 忍 妊 任 韌 人"},
            {"no","の","乃 野 能 農 納"},
            {"nobe","のべ","延 述 陳"},
            {"noboru","のぼる","登 昇 上"},
            {"nomi","のみ","蚤 飲 呑"},
            {"nomu","のむ","飲"},
            {"nori","のり","乗 法 糊 則"},
            {"nou","のう","農 能 膿 悩 濃"},
            {"nu","ぬ","抜 奴 怒 乃 脳 沼 縫 濁 弩"},
            {"nugu","ぬぐ","脱"},
            {"nuu","ぬう","縫 繍"},
            {"nya","にゃ","若 猫 薔薇"},
            {"nyo","にょ","女 如 尿 嬢 妊 柔 迩 賑 尓 珥 邇 韮 鈍"},
            {"nyu","にゅ","入 乳 肉"},
            {"o","お","尾 王 央 横 汚 応 往 押 奥 緒 億 屋 乙 穏 憶 卸 凹 甥 鴎 牡 岡 沖 荻 桶 臆"},
            {"oku","おく","置"},
            {"okuru","おくる","送"},
            {"omoshiroi","おもしろい","面白 有趣"},
            {"ou","おう","鴎 王 欧 殴 央"},
            {"owaru","おわる","終"},
            {"pa","ぱ","八 派 拍 破 波"},
            {"pai","ぱい","配 廃 杯 徘 排"},
            {"pe","ぺ","平 片 偏 辺 返"},
            {"pi","ぴ","匹 非 被 批 否"},
            {"po","ぽ","捕 法 方 奉 歩 保"},
            {"pou","ぽう","報 膨 豊 峰 邦 方"},
            {"pu","ぷ","負 普 布 付 赴 扶"},
            {"pya","ぴゃ","票"},
            {"pyo","ぴょ","評"},
            {"pyu","ぴゅ","浮"},
            {"ra","ら","羅 良 来 酪 藍 落 裸 絡 頼 雷 螺 辣 拉 喇 蘿 瘰 邏 臘 嵐 爛"},
            {"rai","らい","来 雷 頼 嵐 例"},
            {"re","れ","列 烈 劣 練 戻 礼 令 例 冷 励 霊 零 嶺 怜 玲 鈴 隷 麗 澪 羚"},
            {"rei","れい","冷 零 例 礼 励 鈴"},
            {"renji","れんじ","錬冶"},
            {"resutoran","れすとらん","料理店"},
            {"ri","り","利 理 痢 璃 栗 里 吏 離 梨 裏 陸 律 履 莉 李 裡 鯉 哩"},
            {"rin","りん","臨 林 隣 輪 倫 燐 麟"},
            {"ro","ろ","路 労 老 露 浪 録 論 炉 朗 郎 狼 廊 婁 魯 櫓 蝋 濾 璐 硯 六 鹿 楼"},
            {"rou","ろう","労 廊 狼 漏 浪 朗 老"},
            {"ru","る","留 流 瑠 竜 粒 呂 如 乳"},
            {"rya","りゃ","旅 良 領 寮 了 料"},
            {"ryo","りょ","良"},
            {"ryokou","りょこう","旅行"},
            {"ryou","りょう","料 領 陵 寮 糧 両 量 涼"},
            {"ryouri","りょうり","料理"},
            {"ryu","りゅ","龍 柳 流 隆 竜 留 粒 硫 慮 琉 瘤 劉"},
            {"ryuu","りゅう","竜 龍 流"},
            {"sa","さ","左 砂 笹 刺 咲 沙 唆 砕 差 査 作 茶 殺 冊 冴 佐 瑳 皐 嵯 鮭 撒 挿 桜 遡 詐"},
            {"sagasu","さがす","探"},
            {"sai","さい","済 最 犀 彩 祭 砦 際 砕 才 災 斎"},
            {"saka","さか","坂 逆 阪"},
            {"sakaki","さかき","榊 堺"},
            {"saki","さき","先"},
            {"sakura","さくら","桜 咲良"},
            {"samui","さむい","寒"},
            {"satsu","さつ","札 冊 拶 薩"},
            {"se","せ","背 世 姓 青 清 制 成 勢 性 整 静 盛 聖 誠 精 請 妻 斉 隻 脊 婿 斥 戚 拙 窃 摂 醒 脆 砌 棲 晰 蝉 鮭 瀬 是 雪 責 説"},
            {"sei","せい","清 成 誠 生 姓 精 正 棲 制 婿"},
            {"sekai","せかい","世界"},
            {"sen","せん","僉 戦 腺 線 栓 専 千 泉 繊"},
            {"setsumei","せつめい","説明"},
            {"sha","しゃ","社 写 者 車 謝 赦 遮"},
            {"shashin","しゃしん","写真"},
            {"shi","し","志 思 詩 資 師 氏 旨 糸 司 祉 子 市 止 私 誌 示 歯 史 士 刺 枝 紙 視 詞 脂 紫 肢 至 伺 滋 芝 摯 梓 雌 屍 嗣 賜 蒔 孜 諮 斯 偲 柴 縞 蕊 餌 邇 支 仕 施 始 之 四"},
            {"shiba","しば","柴 芝 斯波"},
            {"shigoto","しごと","仕事"},
            {"shimeru","しめる","閉"},
            {"shimo","しも","下 霜"},
            {"shin","しん","真 新 芯 診"},
            {"shinrai","しんらい","信頼"},
            {"shiro","しろ","白 城 代"},
            {"shiru","しる","知"},
            {"sho","しょ","所 初 書 処 諸 署 庶 暑 緒 渚 曙 薯 藷"},
            {"shou","しょう","小 証 礁 賞 章 勝 掌 彰"},
            {"shu","しゅ","種 州 手 首 主 取"},
            {"shukudai","しゅくだい","宿題"},
            {"shuppatsu","しゅっぱつ","出発"},
            {"shuu","しゅう","週 秋 襲 袖 州 羞 衆 集"},
            {"so","そ","荘 宗 倉 捜 曾 素 祖 組 訴 措 租 粗 阻 僧 添 喪 双 掃 挿 痩 窓 綜 躁 遡 唆 嗦 詑 簇 蘇 酥 走 争 葬 曽 則 損 燥"},
            {"sodatsu","そだつ","育"},
            {"sode","そで","袖 曽出"},
            {"sora","そら","空 昊 宇宙 宙"},
            {"soto","そと","外 其外"},
            {"sou","そう","創 痩 相 総 想 挿 双 燥"},
            {"soudan","そうだん","相談"},
            {"su","す","州 主 守 酒 種 須 周 数 過 巣 寸 枢 酢 崇 据 粋 鈴 裾 摺 簀 洲 栖 錫 素 進 涼 透 巢 住 寿"},
            {"sugiru","すぎる","過"},
            {"sumu","すむ","住 済 澄"},
            {"suna","すな","砂 沙"},
            {"suru","する","為"},
            {"susumu","すすむ","進"},
            {"ta","た","汰 妥 唾 多 宅 他 太 田 立 打 隊 帯 待 態 替 貸 退 逮 泰 体 耐 袋 舵 堆 黛 楕 陀 騨 躱 駄"},
            {"taberu","たべる","食"},
            {"taeru","たえる","耐"},
            {"tagui","たぐい","類"},
            {"tai","たい","体 腿 胎 対 待 態 耐 堆 大 代 台 隊"},
            {"taihen","たいへん","大変"},
            {"taiyou","たいよう","太陽"},
            {"take","たけ","竹 丈 岳"},
            {"tama","たま","玉 魂 球 弾"},
            {"tamesu","ためす","試"},
            {"tan","たん","炭 端 誕 短 単 歎 坦"},
            {"tani","たに","谷 渓 谿"},
            {"tanoshii","たのしい","楽"},
            {"tasukeru","たすける","助"},
            {"tatakau","たたかう","戦"},
            {"tatsu","たつ","立 建 絶"},
            {"tazuneru","たずねる","訪"},
            {"te","て","手 定 的 鉄 点 徹 撤 転 天 展 店 添 纏 典 貼 銭 顛 甜 填 輾 擶 籐 寺 出 庭 亭 照"},
            {"tei","てい","偵 締 定 低 堤 停 廷 梯"},
            {"teire","ていれ","手入"},
            {"ten","てん","点 展 天 篆 添 店 纏"},
            {"tenki","てんき","天気"},
            {"tetsu","てつ","鉄"},
            {"to","と","答 塔 倒 島 討 都 東 度 登 等 頭 糖 党 湯 統 冬 棟 藤 悼 騰 闘 憧 祷 萄 塘 鴇 籐 刀 桃 十 斗 戸 吐 渡"},
            {"tobu","とぶ","飛"},
            {"tojiru","とじる","閉"},
            {"tokeru","とける","溶"},
            {"toki","とき","時"},
            {"tomaru","とまる","止"},
            {"tomeru","とめる","止"},
            {"tomodachi","ともだち","友達"},
            {"tori","とり","鳥 取 捕"},
            {"toru","とる","取"},
            {"toshi","とし","都市"},
            {"tou","とう","東 等 統 塔 蕩 棟 湯 憧"},
            {"tsu","つ","着 撮 卒 膝 続 津 都 通 筒 罪 釣 束 痛 妻 費 次 対 追 築 調 墜 鎚 槌 漬 坪 綴 銚 潰 唾 椎 礫 杖 粒 辻 槻 突"},
            {"tsubureru","つぶれる","潰"},
            {"tsuchi","つち","土"},
            {"tsuge","つげ","柘植 告"},
            {"tsugu","つぐ","次"},
            {"tsui","つい","終 遂 就"},
            {"tsuka","つか","塚 柄 束"},
            {"tsukau","つかう","使"},
            {"tsukeru","つける","付"},
            {"tsuki","つき","月 付 築"},
            {"tsukue","つくえ","机"},
            {"tsukuru","つくる","作"},
            {"tsumetai","つめたい","冷"},
            {"tsuyu","つゆ","露 梅雨"},
            {"tsuzukeru","つづける","続"},
            {"u","う","雨 迂 宇 右 羽 運 雲 芋 渦 浦 瓜 嘘 閏 鬱 丑 臼 烏"},
            {"uchi","うち","内 家 打"},
            {"ugoku","うごく","動"},
            {"ukaberu","うかべる","浮"},
            {"umareru","うまれる","生"},
            {"umi","うみ","海"},
            {"umu","うむ","産"},
            {"un","うん","雲 運 蘊 暈"},
            {"unten","うんてん","運転"},
            {"urasu","うらす","熟"},
            {"uru","うる","売"},
            {"usui","うすい","薄"},
            {"utau","うたう","歌"},
            {"utsu","うつ","打"},
            {"wa","わ","和 我 波 羽 輪 瓦 倭 話 賄 惑 脇 湾 腕 鷲 亘 椀 碗 彎"},
            {"wai","わい","外 歪"},
            {"wakareru","わかれる","別"},
            {"wakaru","わかる","分"},
            {"waku","わく","沸"},
            {"warau","わらう","笑"},
            {"wataru","わたる","渡 亙 亘"},
            {"watasu","わたす","渡"},
            {"we","ゑ","絵 衞 恵"},
            {"wi","ゐ","維 井"},
            {"wo","を","左 遠 央 王 往"},
            {"woo","をう","翁"},
            {"ya","や","夜 矢 谷 耶 野 也 屋 弥 家 約 役 八 柳 愉 癒 愈 柚 薮 靖 椰 冶"},
            {"yabureru","やぶれる","破"},
            {"yai","やい","崖 椰"},
            {"yakeru","やける","焼"},
            {"yaku","やく","訳 役 約 厄"},
            {"yakusoku","やくそく","約束"},
            {"yama","やま","山 病"},
            {"yameru","やめる","止"},
            {"yappari","やっぱり","矢張 軈"},
            {"yaru","やる","遣"},
            {"yasashii","やさしい","優"},
            {"yasumi","やすみ","休"},
            {"yo","よ","与 余 用 予 夜 容 羊 洋 要 葉 曜 四 世 様 陽 誉 幼 庸 揚 溶 揺 窯 謡 遥 瑶 耀 恙 沃 慾 輿 妖"},
            {"yobu","よぶ","呼"},
            {"yomu","よむ","読"},
            {"yoru","よる","依 因 選"},
            {"you","よう","要 揺 洋 用 曜 妖 庸 陽"},
            {"yowai","よわい","弱"},
            {"yoyaku","よやく","予約"},
            {"yu","ゆ","由 油 友 幽 湯 優 輸 有 遊 癒 勇 悠 裕 誘 融 唯 雄 邑 柚 祐 宥 鑓 湧 揖"},
            {"yuki","ゆき","雪"},
            {"yume","ゆめ","夢"},
            {"yureru","ゆれる","揺"},
            {"yuu","ゆう","憂 友 優 悠 祐 佑 有 幽 勇 雄"},
            {"za","ざ","座 沙 査 雑 錆 挫 坐"},
            {"zai","ざい","財 罪 犀 剤 在 材"},
            {"zaki","ざき","崎 岬 埼"},
            {"zan","ざん","斬 残 讃"},
            {"ze","ぜ","是 責 跡 絶 製"},
            {"zei","ぜい","税 贅 贄"},
            {"zen","ぜん","全 禅 漸 善 膳"},
            {"zo","ぞ","像 雑 然 蔵 憎 塑 遡"},
            {"zou","ぞう","憎 造 像 臓"},
            {"zu","ず","図 住 菓 頭 女"},
            {"zu","づ","津 豆 図 都 毒 頭 続"},
            {"zutto","ずっと","続"},

            {NULL, NULL}
};
#endif





void japanese_input_proc(lv_obj_t * obj)
{
    lv_100ask_pinyin_ime_t * japanese_ime = (lv_100ask_pinyin_ime_t *)obj;

    //japanese_ime->cand_str = japanese_search_matching(obj, japanese_ime->input_char, &japanese_ime->cand_num);
    //if (japanese_ime->cand_str == NULL) 
    //{
    //    return;
    //}
    printf("=====japanese_input_proc====\n");
    printf("japanese_ime->input_char:%s\n",japanese_ime->input_char);
    lv_100ask_dict_t *cand_dict = japanese_search_matching_dict(obj, japanese_ime->input_char, &japanese_ime->cand_num);
    if (cand_dict == NULL) 
    {
        return;
    }
    printf("dict:%s.%s,%s\n",cand_dict->py,cand_dict->py_mb,cand_dict->py_hz);
    japanese_ime->py_page = 0;
printf("=====japanese_input_proc2====\n");
    for(uint8_t i = 0; i < LV_100ASK_PINYIN_IME_CAND_TEXT_NUM; i++)
    {
        printf("=====loop %d====\n",i);
        memset(japanese_ime->btnm_pinyin_sel_user[i], 0x00, CAND_STR_MAX_LEN);
        japanese_ime->btnm_pinyin_sel_user[i][0] = ' ';
    }
    printf("=====japanese_input_proc3====\n");
    char* p = cand_dict->py_hz;
    // fill buf
    if(strlen(cand_dict->py_mb)<=CAND_STR_MAX_LEN)
        strcpy(japanese_ime->btnm_pinyin_sel_user[0],cand_dict->py_mb);
    else
        strncpy(japanese_ime->btnm_pinyin_sel_user[0],cand_dict->py_mb,CAND_STR_MAX_LEN);
    int len = strlen(cand_dict->py_hz);
    int candeindex=1;
    printf("=====japanese_input_proc4====\n");
    while(candeindex<LV_100ASK_PINYIN_IME_CAND_TEXT_NUM)
    {
        char*q = strchr(p,' ');
        if(q && (q-p>0) )
        {
            int substr_len = q-p;
            strncpy(japanese_ime->btnm_pinyin_sel_user[candeindex],p,substr_len);
            japanese_ime->btnm_pinyin_sel_user[candeindex][substr_len]='\0';
            candeindex++;
            p = q+1;

        }
        else{
            //处理最后一个候选
            if(p &&strlen(p)>0)
            {
                strncpy(japanese_ime->btnm_pinyin_sel_user[candeindex],p,strlen(p));
                japanese_ime->btnm_pinyin_sel_user[candeindex][strlen(p)]='\0';
                candeindex++;
            }
            break;
        }
    }
    printf("=====japanese_input_proc5====\n");
    //for(uint8_t i = 0; (i < japanese_ime->cand_num && i < LV_100ASK_japanese_IME_CAND_TEXT_NUM); i++)
    lv_obj_clear_flag(japanese_ime->cand_panel, LV_OBJ_FLAG_HIDDEN);
}


void init_japanese_dict(lv_obj_t * obj, lv_100ask_dict_t * dict)
{
    char headletter = 'a';
    uint16_t offset_sum = 0;
    uint16_t offset_count = 0;
    uint16_t letter_calc = 0;

    for(uint16_t i = 0; ; i++)
    {
        if ((NULL == (dict[i].py)) || (NULL == (dict[i].py_mb)))
        {
            headletter = dict[i-1].py[0];
            letter_calc = headletter - 'a';
            py_num[letter_calc] = offset_count;
            break;
        }   
        if (headletter == (dict[i].py[0]))
        {
            offset_count++;
        }
        else
        {
            headletter = dict[i].py[0];
            letter_calc = headletter - 'a';
            py_num[letter_calc - 1] = offset_count;
            offset_sum += offset_count;
            py_pos[letter_calc] = offset_sum;

            offset_count = 1;
        }       
    }
}

static lv_100ask_dict_t * japanese_search_matching_dict(lv_obj_t * obj, char * strInput_py_str, uint16_t * cand_num)
{
    lv_100ask_pinyin_ime_t * japanese_ime = (lv_100ask_pinyin_ime_t *)obj;
    lv_100ask_dict_t * cpHZ;
    uint8_t i, cInputStrLength = 0, offset;
    volatile uint8_t count = 0;

    if(*strInput_py_str == '\0')    return NULL;
    //if(*strInput_py_str == 'i')     return NULL;
    //if(*strInput_py_str == 'u')     return NULL;
    //if(*strInput_py_str == 'v')     return NULL;

    offset = strInput_py_str[0] - 'a';
    cInputStrLength = strlen(strInput_py_str);
    
    cpHZ  = &lv_100ask_def_japanese_dict[py_pos[offset]];
    count = py_num[offset];

    while(count--)
    {
        for(i = 0; i < cInputStrLength; i++)
        {
            if(*(strInput_py_str + i) != *((cpHZ->py) + i))
            {
                break;
            }
        }
        // perfect match
        if(cInputStrLength == 1 || i == cInputStrLength)
        {
            // The Chinese character in UTF-8 encoding format is 3 bytes
            //* cand_num = 1;//strlen((const char*)(cpHZ->py_mb)) / 3;
            //第二列+第三列
            * cand_num = 1;
            return cpHZ;
        }       
        cpHZ++;
    }
    return NULL;
}


#endif  /*LV_USE_japanese_IME*/
